package cn.zbh.pet.service.impl;

import cn.zbh.basic.service.impl.BasicServiceImpl;
import cn.zbh.pet.domain.Pet;
import cn.zbh.pet.domain.PetDetail;
import cn.zbh.pet.domain.PetType;
import cn.zbh.pet.mapper.PetDetailMapper;
import cn.zbh.pet.mapper.PetMapper;
import cn.zbh.pet.service.IPetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.xml.crypto.Data;
import java.util.Date;
import java.util.List;

@Service
public class PetServiceImpl extends BasicServiceImpl<Pet> implements IPetService {
    @Autowired
    private PetMapper petMapper;
    @Autowired
    private PetDetailMapper petDetailMapper;
    @Override
    public void add(Pet pet) {
        petMapper.add(pet);
        //获取宠物详情
        PetDetail petDetail = pet.getPetDetail();

        petDetail.setPet_id(pet.getId());
        petDetailMapper.add(petDetail);
    }

    @Override
    public void update(Pet pet) {
        petMapper.update(pet);
        petDetailMapper.update(pet.getPetDetail());
    }

    /**
     * 上架
     * @param ids
     */
    @Override
    public void onsale(List<Long> ids) {
        // 1审核，通过则上架，没通过直接自定义异常，保存一条数据

        // 该状态
        // 上架时间
        Date date = new Date();
        petMapper.onSale(ids,date);
    }

    /**
     * 下架
     * @param ids
     */
    @Override
    public void offsale(List<Long> ids) {
        Date date = new Date();
        petMapper.offsale(ids,date);


    }
}
